<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <input type="file" name="" id="">
<img src="" alt="">

  <script>
    const inp = document.querySelector('input')
    const img = document.querySelector('img')
    inp.onchange=function(e){
      //change事件会在用户选择文件时触发
      //e.target.files[0]=>获取用户选择的那个文件
      const file=e.target.files[0]
      img.src=URL.createObjectURL(file)
    }
  </script>
</body>
</html>